
#ifndef UTILITY_H
#define UTILITY_H

#include <stdio.h>
#include "macros.h"

C_BEGIN_DECLS

#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif

#define DEBUG(output) \
	printf("%s : line %d, function %s.\n%s\n", __FILE__, __LINE__, __FUNCTION__, (output))

#define RES(output) \
	DEBUG(output); \
	return

#define RES_INVAL(output) \
	DEBUG(output); \
	return -1

#define RES_NULL(output) \
	DEBUG(output); \
	return NULL

#define RES_FALSE(output) \
	DEBUG(output); \
	return FALSE

#define G_ERROR_RES(error) \
	DEBUG(error->message); \
	g_error_free(error); \
	return

#define G_ERROR_RES_INVAL(error) \
	DEBUG(error->message); \
	g_error_free(error); \
	return -1

#define G_ERROR_RES_NULL(error) \
	DEBUG(error->message); \
	g_error_free(error); \
	return NULL

#define G_ERROR_RES_FALSE(error) \
	DEBUG(error->message); \
	g_error_free(error); \
	return FALSE

void zombie_handler(int signal);
// Deal with SIGPIPE:
// 	1. Close client before server.
// 	2. Server send when client has been closed.
void pipe_handler(int signal);

C_END_DECLS

#endif	// UTILITY_H

